﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Linq;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using BLL;
using DAL;
using NLog;

namespace QLTTTH
{
    public partial class frmThongTinMonHoc : DevExpress.XtraEditors.XtraForm
    {
        private static Logger logger = LogManager.GetCurrentClassLogger();

        public frmThongTinMonHoc()
        {
            InitializeComponent();
        }

        private void btnHuyBo_Click(object sender, EventArgs e)
        {
            ResetControl();
            this.Close();
        }

        public void FillControl(MonHoc mh)
        {
            this.txtMaMH.Text = mh.MaMH.ToString();
            this.txtTenMH.Text = mh.TenMH;
            this.txtThoiGianHoc.Text = mh.ThoiGianHoc;
        }

        private void ResetControl()
        {
            this.txtMaMH.ResetText();
            this.txtTenMH.ResetText();
            this.txtThoiGianHoc.ResetText();
        }

        public  MonHoc GetMonHoc()
        {
            MonHoc mh = new MonHoc();
            if (!txtMaMH.Text.ToString().Equals(""))
            {
                mh.MaMH = int.Parse(txtMaMH.Text.ToString());   
            }
            mh.TenMH = txtTenMH.Text;
            mh.ThoiGianHoc = txtThoiGianHoc.Text;

            return mh;
        }

        public delegate void SendData(MonHoc mh);

        public SendData sendData;

        private void btnLuu_Click(object sender, EventArgs e)
        {
            if(sendData != null)
            {
                var vResult = new MonHocManager().Validate(GetMonHoc());
                if (vResult.Valid)
                {
                    sendData(GetMonHoc());
                    DialogResult = DialogResult.OK;
                    this.Close();
                }
                else
                {
                    logger.Info(vResult.ToErrorString());
                    XtraMessageBox.Show(vResult.ToString(), "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
        }

    }
}